package cn.ijero.waterfallflow;

import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import cn.ijero.waterfallflow.data.FlowData;

public class ListAdapter extends BaseQuickAdapter<FlowData.Data, BaseViewHolder> {

    public ListAdapter() {
        super(R.layout.item_list);
    }

    @Override
    protected void convert(BaseViewHolder holder, FlowData.Data data) {
        holder.getView(R.id.imageView).getLayoutParams().height = data.getHeight();

        int widthPixels = getContext().getResources().getDisplayMetrics().widthPixels;

        Glide.with(getContext())
                .asDrawable()
                .load(data.getMiddleURL())
                .override((int) (widthPixels * 0.5f), data.getHeight())
                .transform(new CenterCrop(), new RoundedCorners(40))
                .into((ImageView) holder.getView(R.id.imageView));
    }
}
